package org.afs.gescol.edt.api.test.mock;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.afs.gescol.core.dto.classes.FullSchoolClassDto;
import org.afs.gescol.core.dto.subject.FullSubjectDto;
import org.afs.gescol.core.dto.time.HourlyDto;
import org.afs.gescol.core.dto.time.PeriodDto;
import org.afs.gescol.core.dto.time.SchoolHoursDto;
import org.afs.gescol.core.service.interfaces.GlobalParamsServices;
import org.scub.foundation.framework.base.dto.IdLabelDto;

/**
 * @author Kobla GBENYO (kobla.gbenyo@gmail.com)
 */
public class GlobalParamsServicesImpl implements GlobalParamsServices {

    @Override
    public List<FullSchoolClassDto> getSchoolClassFullData(Long cycleId) {
        final List<FullSchoolClassDto> classes = new ArrayList<FullSchoolClassDto>();
        classes.add(getClasse(3L, getListSubjects()));
        return classes;
    }

    @Override
    public SchoolHoursDto getSchoolHoursParams(Long cycleId) {
        return new SchoolHoursDto(5, 3, 7);
    }

    private FullSchoolClassDto getClasse(Long idClass, List<FullSubjectDto> listSubjects) {
        final FullSchoolClassDto fsc = new FullSchoolClassDto();
        fsc.setId(idClass);
        fsc.setSubjects(listSubjects);
        return fsc;
    }

    private List<FullSubjectDto> getListSubjects() {
        final List<FullSubjectDto> fsl = new ArrayList<FullSubjectDto>();
        final FullSubjectDto fs = new FullSubjectDto();
        fs.setId(3L);
        fs.setWeeklyHoursVolume(15);
        fs.setTeachers(Arrays.asList(new Long[]{1L}));
        fsl.add(fs);
        return fsl;
    }

    @Override
    public PeriodDto getCurrentperiod(Long cycleId) {
        final PeriodDto period = new PeriodDto();
        period.setId(1L);
        period.setLabel("Trimestre courrant");
        period.setBeginDate(new Date());
        period.setEndDate(new Date());
        period.setYear(new IdLabelDto(1L, "2014-2015"));
        return period;
    }

    @Override
    public List<HourlyDto> getHourly(Long cycleId) {
        final List<HourlyDto> hourly = new ArrayList<HourlyDto>();
        final String[] labels = new String[]{"1ère Heure", "2ème Heure", "3ème Heure", "4ème Heure", "5ème Heure", "6ème Heure", "7ème Heure"};
        final Date[] beginHours = new Date[]{getDate(7), getDate(8), getDate(9), getDate(10), getDate(11), getDate(15), getDate(16)};
        final Date[] endHours = new Date[]{getDate(8), getDate(9), getDate(10), getDate(11), getDate(12), getDate(16), getDate(17)};
        for (int i = 0; i < 7; i++) {
            final HourlyDto hour = new HourlyDto();
            hour.setId(new Long(i));
            hour.setOrder(i + 1);
            hour.setLabel(labels[i]);
            hour.setBeginHour(beginHours[i]);
            hour.setEndHour(endHours[i]);
            hourly.add(hour);
        }
        return hourly;
    }

    private Date getDate(int i) {
        return new Date(70, 0, 1, i, 0);
    }

}
